import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-25
 * Time: 19:17
 */
public class test_1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int f1 = 0;
            int f2 = 1;
            while (f2 < n) {
                int tmp = f1;
                f1 = f2;
                f2 = tmp + f2;

            }

            int min=Math.min(f2-n,n-f1);
            System.out.println(min);
        }
    }
}
